import axios from "axios";
import http from "@/api/http.js";
const baseUrl = "http://localhost:8091";
const defeceRequest={
    // 分页查询
    loadDefeces(defece,page=1,limit=10,callBack){
        let url = baseUrl + "/defece/selectAll?page=" + page + "&limit=" + limit;
        if (defece){
            if (defece.defeceName){
                url += "&defeceName=" + defece.defeceName;
            }
            if (defece.defeceType){
                url += "&defeceType=" + defece.defeceType;
            }
            if (defece.defeceLevel){
                url += "&defeceLevel=" + defece.defeceLevel;
            }
        }
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callBack(res.data);
        })
    },
//     新增缺陷
    addDefece(defece,callBack){
        let url = baseUrl + "/defece/add";
        axios.post(url,defece,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callBack(res.data);
        })
    },
//     根据id查询缺陷信息
    loadSelectDefeceById(defeceId,callBack){
        let url = baseUrl + "/defece/selectById?defeceId=" + defeceId;
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callBack(res.data);
        })
    },
//     根据id修改缺陷信息
    loadUpdateDefece(defece,callBack){
        let url = baseUrl + "/defece/update";
        axios.post(url,defece,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callBack(res.data);
        })
    },
//     根据id删除缺陷信息
    loadDeleteDefeceById(defeceId,callBack){
        let url = baseUrl + "/defece/delete?defeceId=" + defeceId;
        axios.delete(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callBack(res.data);
        })
    }
}
export default defeceRequest